
    const appid = 'wx9382bcb156fe7439'
    const appsecret = "1115a6551dbb95d3229039188eb64120"
    var i = 1
    i = sessionStorage.getItem('i')
    // server-address

    // api url
    // 获取微信codekey   注释掉，否则只能在微信开发者工具运行
    var code = getUrlKey("code");
    // if (!code) {
    //     let urlNow = encodeURIComponent('https://cakewxfr.haguodutimes.com/');
    //     // let scope='snsapi_userinfo';    //snsapi_userinfo snsapi_base   //静默授权 用户无感知

    //     let url =
    //         "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
    //         appid +
    //         "&redirect_uri=" +
    //         urlNow +
    //         "&response_type=code&scope=snsapi_userinfo#wechat_redirect";
    //     window.location.href = url;
    // }

    function getUrlKey(name) {
        //获取url 参数
        return (
            decodeURIComponent(
                (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
                    location.href
                ) || [, ""])[1].replace(/\+/g, "%20")
            ) || null
        );
    }


    setTimeout(function () {
        if (i != null) {       
        } else {
            getOpenid(code)
        }

    }, 500)

    function getOpenid(code) {
        var timo = {
            code: code,
        }
        $.ajax({
            url: 'https://cakewxbk.haguodutimes.com/handler/getOpenid',
            type: 'post',
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify(timo),
            success: function (data) {
                sessionStorage.setItem('openId', data.openId)
            }
        })
    }

// 视图js
var quantity = 0
var quantity1 = 0
var quantity2 = 0
var quantity3 = 0
var quantity4 = 0
var name_quantity = ''
sessionStorage.setItem('goodsId1', '0')
sessionStorage.setItem('goodsId2', '0')
sessionStorage.setItem('goodsId3', '0')
sessionStorage.setItem('goodsId4', '0')

// 下一步编写价格  数量*单价
$('.event1').click(function () {
    quantity++
    name_quantity = '蛋糕1' + '-' + quantity
    sessionStorage.setItem('goodsId1', name_quantity)
    $(this).prev().html(quantity)
    var jiage = $(this).parent().prev().children('.jiage').html()


    var aa = quantity + quantity1 + quantity2 + quantity3

    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)

    console.log(aa);
    $('.TotalQuantity').html(aa)
    $(this).next().html(quantity)

    $('.rightBox').find('.details1').find('.total').html(quantity)

})
$('.event2').click(function () {
    quantity1++
    name_quantity = '蛋糕2' + '-' + quantity1
    sessionStorage.setItem('goodsId2', name_quantity)

    $(this).prev().html(quantity1)

    var jiage = $(this).parent().prev().children('.jiage').html()

    var aa = quantity + quantity1 + quantity2 + quantity3
    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)
    $('.TotalQuantity').html(aa)
    $('.rightBox').find('.details2').find('.total').html(quantity1)
})
$('.event3').click(function () {
    quantity2++
    name_quantity = '蛋糕3' + '-' + quantity2
    sessionStorage.setItem('goodsId3', name_quantity)

    $(this).prev().html(quantity2)

    var jiage = $(this).parent().prev().children('.jiage').html()


    var aa = quantity + quantity1 + quantity2 + quantity3
    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)
    $('.TotalQuantity').html(aa)
    $('.rightBox').find('.details3').find('.total').html(quantity2)
})
$('.event4').click(function () {
    quantity3++
    name_quantity = '蛋糕4' + '-' + quantity3

    sessionStorage.setItem('goodsId4', name_quantity)

    $(this).prev().html(quantity3)

    var jiage = $(this).parent().prev().children('.jiage').html()


    var aa = quantity + quantity1 + quantity2 + quantity3
    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)
    $('.TotalQuantity').html(aa)
    $('.rightBox').find('.details4').find('.total').html(quantity3)

})
$('.reduceevent1').click(function () {
    quantity--
    if (quantity <= 0) {
        $(this).next().html(0)
        quantity = 0
    }
    name_quantity = '蛋糕1' + '-' + quantity
    sessionStorage.setItem('goodsId1', name_quantity)
    $(this).next().html(quantity)
    var jiage = $(this).parent().prev().children('.jiage').html()
    $('.zongji').html('￥' + zongshu)
    var aa = quantity + quantity1 + quantity2 + quantity3
    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)

    console.log(aa);
    $('.TotalQuantity').html(aa)
    $('.rightBox').find('.details1').find('.total').html(quantity)

})
$('.reduceevent2').click(function () {
    quantity1--
    if (quantity1 <= 0) {
        $(this).next().html(0)
        quantity1 = 0
    }
    name_quantity = '蛋糕2' + '-' + quantity1
    sessionStorage.setItem('goodsId2', name_quantity)
    $(this).next().html(quantity1)

    bb =
        $(this).next().html()
    var jiage = $(this).parent().prev().children('.jiage').html()
    $('.zongji').html('￥' + zongshu)
    var aa = quantity + quantity1 + quantity2 + quantity3
    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)

    $('.TotalQuantity').html(aa)
    $('.rightBox').find('.details2').find('.total').html(quantity1)
})
$('.reduceevent3').click(function () {

    quantity2--
   

    if (quantity2 <= 0) {
        $(this).next().html(0)
        quantity2 = 0

    }
    name_quantity = '蛋糕3' + '-' + quantity2
    sessionStorage.setItem('goodsId3', name_quantity)
    $(this).next().html(quantity2)


    var jiage = $(this).parent().prev().children('.jiage').html()

    var aa = quantity + quantity1 + quantity2 + quantity3
    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)

    $('.TotalQuantity').html(aa)
    $('.rightBox').find('.details3').find('.total').html(quantity2)
})
$('.reduceevent4').click(function () {
    quantity3--  
    if (quantity3 <= 0) {
        $(this).next().html(0)
        quantity3 = 0
    }
    name_quantity = '蛋糕4' + '-' + quantity3
    sessionStorage.setItem('goodsId4', name_quantity)
    $(this).next().html(quantity3)

    bb =
        $(this).next().html()
    var jiage = $(this).parent().prev().children('.jiage').html()
    var aa = quantity + quantity1 + quantity2 + quantity3
    var zongshu = aa * jiage
    zongshu = zongshu.toFixed(2)
    sessionStorage.setItem('zongshu', zongshu)
    $('.zongji').html('￥' + zongshu)

    $('.TotalQuantity').html(aa)
    $('.rightBox').find('.details4').find('.total').html(quantity3)
})

$('.scar').click(function () {
    if (quantity <= 0) {
        console.log(1);
        $('.xinxi .details1').hide()
    }
    if (quantity1 <= 0) {
        $('.xinxi .details2').hide()
    }
    if (quantity2 <= 0) {
        $('.xinxi .details3').hide()
    }
    if (quantity3 <= 0) {
        $('.xinxi .details4').hide()
    }
    if (quantity > 0) {
        console.log(2222);
        $('.xinxi .details1').show()
    }
    if (quantity1 > 0) {
        $('.xinxi .details2').show()
    }
    if (quantity2 > 0) {
        $('.xinxi .details3').show()
    }
    if (quantity3 > 0) {
        $('.xinxi .details4').show()
    }

    quantity4 = 1
    $('.mask').toggle()
    $('.xinxi').find('.details1').find('.total').html(quantity)
    $('.xinxi').find('.details2').find('.total').html(quantity1)
    $('.xinxi').find('.details3').find('.total').html(quantity2)
    $('.xinxi').find('.details4').find('.total').html(quantity3)
    if (quantity4 == 1) {
        console.log(789);

        $('.rightBox').find('.details1').find('.total').html(quantity)
        $('.rightBox').find('.details2').find('.total').html(quantity1)
        $('.rightBox').find('.details3').find('.total').html(quantity2)
        $('.rightBox').find('.details4').find('.total').html(quantity3)
        $('.xinxi').show();
        $('.maskheader').show();
    }
})

$('.qingkong').click(function () {
    $('.rightBox').find('.details1').find('.total').html(0)
    $('.rightBox').find('.details2').find('.total').html(0)
    $('.rightBox').find('.details3').find('.total').html(0)
    $('.rightBox').find('.details4').find('.total').html(0)
    $('.xinxi').find('.details1').find('.total').html(0)
    $('.xinxi').find('.details2').find('.total').html(0)
    $('.xinxi').find('.details3').find('.total').html(0)
    $('.xinxi').find('.details4').find('.total').html(0)
    $('.TotalQuantity').html(0)
    quantity = 0
    quantity1 = 0
    quantity2 = 0
    quantity3 = 0
    quantity4 = 0
    $('.zongji').html('--')
})

$('.settlement').click(function () {

    sessionStorage.setItem('quantity', quantity)
    sessionStorage.setItem('quantity1', quantity1)
    sessionStorage.setItem('quantity2', quantity2)
    sessionStorage.setItem('quantity3', quantity3)

    window.location.href = 'settlement.html'
})
$('.guanbi').click(function (event) {
    // event.target == this
    event.stopPropagation();
    event.preventDefault();
    console.log(456);
    $('.mask').hide();
    $('.xinxi').hide();
    $('.maskheader').hide();
})